package com.purong.purong.activity;

import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.flyco.tablayout.SlidingTabLayout;
import com.flyco.tablayout.listener.OnTabSelectListener;
import com.purong.purong.R;
import com.purong.purong.adapter.ViewPagerAdapter;
import com.purong.purong.fragment.SysMsgFragment;
import com.purong.purong.fragment.SysNoticeFragment;

import java.util.ArrayList;

/**
 * Created by zengwenjie on 2017/12/4.
 */
public class InfoCenterActivity extends BaseActivity {
    public static final int PAGE_NOTICE=0x001,PAGE_MSG=0x002;
    private SlidingTabLayout tabLayout;
    private ViewPager mViewPager;
    private ViewPagerAdapter mAdapter;
    private ArrayList<Fragment> fragmentList = new ArrayList<>();
    private ArrayList<String> titleList = new ArrayList<>();
    private int status=PAGE_NOTICE;
    @Override
    public int getRootViewId() {
        return R.layout.activity_info_center;
    }

    @Override
    public void initBundle() {
        super.initBundle();
        status=getIntent().getIntExtra("PAGE",PAGE_NOTICE);
    }

    @Override
    public void initView() {
        tabLayout = (SlidingTabLayout) findViewById(R.id.sliding_tablayout);
        mViewPager = (ViewPager) findViewById(R.id.view_pager);
        SysNoticeFragment sysNoticeFragment=new SysNoticeFragment();
        fragmentList.add(sysNoticeFragment);
        SysMsgFragment sysMsgFragment=new SysMsgFragment();
        fragmentList.add(sysMsgFragment);
        titleList.add("公告");
        titleList.add("消息");
        mAdapter = new ViewPagerAdapter(getSupportFragmentManager(), fragmentList);
        mAdapter.setPageTitle(titleList);
        mViewPager.setAdapter(mAdapter);
        mViewPager.setOffscreenPageLimit(1);

        tabLayout.setViewPager(mViewPager);
        tabLayout.setTabSpaceEqual(true);
        tabLayout.setOnTabSelectListener(new OnTabSelectListener() {
            @Override
            public void onTabSelect(int position) {

            }

            @Override
            public void onTabReselect(int position) {


            }
        });
        if (status==PAGE_MSG){
            tabLayout.setCurrentTab(1);
        }else {
            tabLayout.setCurrentTab(0);

        }
    }

    @Override
    public void initData() {

    }
    public void onClick(View v){
        switch (v.getId()){
            case R.id.left_back:
                finish();
                break;
        }
    }
}
